package com.vf.admin.common.splitpage;

import java.util.List;

public class PageUtil {
    public static PageUtil getInstance(){
        return new PageUtil();
    }
    /**
     * 开始分页
     *
     * @param list
     * @return
     */
    public List startPage(List list, SplitPageBean splitPage) {
        if(list == null){
            return null;
        }
        if(list.size() == 0){
            return null;
        }

        int count = list.size();
        if(splitPage!=null){
            // 将总记录数赋值给splitPageBean对象
            if((int)count > 0){
                splitPage.setTotalCount((int)count);
            }else{
                splitPage.setTotalCount(0);
            }
        }
        List pageList = null;
        if(count>splitPage.getFirstRecord()){
            if( count>=splitPage.getFirstRecord()+(splitPage.getMaxRecord())){
                pageList = list.subList(splitPage.getFirstRecord(), splitPage.getFirstRecord()+(splitPage.getMaxRecord()));
            }else{
                pageList = list.subList(splitPage.getFirstRecord(), count);
            }
            return pageList;
        }else{
            return null;
        }
    }
}
